<template>
  <div class="drawer_box">
    <div
      class="flex_start_start serch_box"
      style="transform: translateX(-11px); margin-bottom: 4px"
    >
      <el-input
        v-model="searchName"
        placeholder="请输入查询姓名"
        class="filter-item"
        style="margin-left: 10px; width: 200px"
      />
      <el-button
        title="查询"
        class="filter-item"
        style="margin-left: 10px"
        type="primary"
        :icon="Search"
        @click="getCriminalInfoSelect"
      >
      </el-button>
    </div>
    <div class="isTable">
      <div class="btn_box">
        <div
          @click="btnClick(item, index)"
          :class="{ isAtv: isIndex == index }"
          class="itemz flex_center_center"
          v-for="(item, index) in jqArrCv"
          :key="index"
        >
          {{ item.name }}
        </div>
      </div>
      <div style="width: 90%; border: 1px solid rgb(23, 88, 158)">
        <el-table
          :data="CriminalInfoSelectList"
          border
          fit
          style="width: 100%"
          highlight-current-row
          height="650"
          stripe
        >
          <!-- <el-table-column type="index" align="center" width="60" label="序号">
        </el-table-column> -->
          <el-table-column label="编号（省）" align="center" width="110">
            <template #default="scope">
              <span>{{ scope.row.provinceCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="姓名" align="center" width="120">
            <template #default="scope">
              <span>{{ scope.row.name }}</span>
            </template>
          </el-table-column>
          <el-table-column label="性别" align="center">
            <template #default="scope">
              <span>{{ scope.row.xb }}</span>
            </template>
          </el-table-column>
          <el-table-column label="名族" align="center">
            <template #default="scope">
              <span>{{ scope.row.mz }}</span>
            </template>
          </el-table-column>
          <el-table-column label="身份证号" align="center">
            <template #default="scope">
              <span>{{ scope.row.account }}</span>
            </template>
          </el-table-column>
          <el-table-column label="地址" align="center" width="260">
            <template #default="scope">
              <span>{{ scope.row.jtzz }}</span>
            </template>
          </el-table-column>
          <el-table-column label="处遇等级" align="center" width="80">
            <template #default="scope">
              <span>{{ scope.row.cylevel }}</span>
            </template>
          </el-table-column>
          <el-table-column label="入监日期" align="center">
            <template #default="scope">
              <span>{{ scope.row.rjrq }}</span>
            </template>
          </el-table-column>
          <el-table-column label="刑起刑止" align="center">
            <template #default="scope">
              <span>{{ scope.row.qr }} - </span>
              <span v-if="scope.row.zr != 'NaN-aN-aN'">{{ scope.row.zr }}</span>
              <span v-else>无期</span>
            </template>
          </el-table-column>
          <el-table-column label="刑期" align="center">
            <template #default="scope">
              <span>{{ scope.row.xq }}</span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="罪名" align="center">
            <template #default="scope">
              <span>{{ scope.row.zm }}</span>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            label="监舍"
            align="center"
            width="80"
          >
            <template #default="scope">
              <span>{{ scope.row.jshName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="床位" align="center" width="60">
            <template #default="scope">
              <span>{{ scope.row.cwh }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="example-pagination-block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :page-size="15"
        layout="prev, pager, next,total"
        :total="total"
      />
    </div>
  </div>
</template>

<script setup>
import http from "@/utils/api";
//需要删除代码
import {
  Search,
  Share,
  Upload,
  TakeawayBox,
  Refresh,
  Collection,
  Plus,
  Loading,
  FolderDelete,
  Back,
} from "@element-plus/icons-vue";
//需要删除代码
import {
  ref,
  watch,
  onMounted,
  onBeforeUnmount,
  reactive,
  onBeforeMount,
  nextTick,
  onUnmounted,
} from "vue";
import { defineProps, defineEmits } from "vue";

let CriminalInfoSelectList = ref([]);
let CriminalInfoSelectText = ref("");
let searchName = ref("");
// 声明年月日 时
let dateSfm = ref("");
let hour = ref("");
let daydata = ref("");

let jqArrCv = ref([]);
let isIndex = ref(0);
let selectValue = ref("");
const total = ref(0);
const page = ref(1);
const limit = ref(15);
const props = defineProps({
  jqArr: {
    type: Array,
    default: [],
  },
});

onBeforeMount(() => {});
watch(
  () => props.jqArr,
  (newValue, oldValue) => {
    if (newValue) {
      if (props.jqArr) {
        jqArrCv.value = JSON.parse(JSON.stringify(props.jqArr));
        let arr = [];
        arr = jqArrCv.value.filter((item) => item.name.includes("监区"));

        jqArrCv.value = arr;
        let allJq = jqArrCv.value.map((itz) => itz.id);
        selectValue.value = allJq[0];
      }
      getFormattedDateTime();
      getCriminalInfoSelect();
    } 
    //需要删除代码
    else {
    }
  },
  {
    deep: true, // 深度监听
    immediate: true, // 立即触发回调
  }
);

// 获取年月日 时
const getFormattedDateTime = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, "0");
  const day = String(now.getDate()).padStart(2, "0");
  const hours = String(now.getHours()).padStart(2, "0");
  const minutes = String(now.getMinutes()).padStart(2, "0");
  const seconds = String(now.getSeconds()).padStart(2, "0");
  dateSfm.value = `${hours}:${minutes}:${seconds}`;
  hour.value = String(now.getHours()).padStart(2, "0");
  daydata.value = `${year}-${month}-${day}`;

  return `${year}-${month}-${day} ${hour.value}`;
};
const btnClick = (item, index) => {
  selectValue.value = item.id;
  isIndex.value = index;
  getCriminalInfoSelect();
};
const getCriminalInfoSelect = async () => {
  let res = await http.zfpt.CriminalInfoSelect({
    page: page.value,
    limit: limit.value,
    criminalNo: "",
    name: searchName.value,
    state: "jnzy,ljtq,jbfr,cjxd,jwzy,jwzx,jhzs,zcfr,zyfr,syfr",
    jsh: "",
    orgId: selectValue.value,
    "location": '',
    "joinDate": '',
  });
  if (res && res.code == 0) {
    CriminalInfoSelectList.value = res.data.data;
    total.value = res.data.total;
    CriminalInfoSelectText.value = "罪犯" + `(${res.data.data.length}人)`;
  }
};
const handleSizeChange = (val) => {};
const handleCurrentChange = (val) => {
  page.value = val;
  getCriminalInfoSelect();
};
</script>

<style scoped lang="scss">
::v-deep .example-pagination-block {
  margin-top: 10px;
  margin-left: 230px;
  .el-pagination.is-background .btn-prev {
    background-color: #34517d3b;
    color: #ffffff;
  }
  .el-pagination.is-background .el-pager li {
    background-color: #34517d3b;
    color: #ffffff;
  }
  .el-pagination.is-background .btn-next {
    background-color: #34517d3b;
    color: #ffffff;
  }
  .el-pagination__total {
    color: #ffffff;
  }
  .el-pager li.is-active {
    background-color: #0768f9d3 !important;
  }
}

::v-deep .serch_box {
  .el-input__wrapper {
    background-color: #ffffffc7;
    box-shadow: (0 0 0 1px #dcdfe600) inset;
  }
  //需要删除的代码
  .el-input__inner {
  }
}

.isTable {
  border-top: 1px solid rgb(23, 88, 158);
  display: flex;
}
::v-deep .isTable .el-table {
  thead tr .el-table__cell {
    border-bottom: none !important;
  }

  .el-table__cell {
    padding: 2px 0 !important;
    background: rgb(8, 38, 78) !important;
  }
  .el-table th.el-table__cell.is-leaf {
    background: rgb(8, 38, 78) !important;
  }
  .el-table .cell {
    font-size: 12px !important;
  }
  .el-table .el-table__cell {
    padding: 2px 4px;
  }
  .el-table td.el-table__cell div {
    box-sizing: border-box;
    color: #ffffff !important;
    height: auto;
    line-height: 38px;
  }
  --el-table-border-color: #ccc0;
  --el-table-border: 1px solid rgb(23, 88, 158);
  .cell {
    height: 30px;
    text-align: center;
    color: white;
    font-size: 12px;
    line-height: 38px;
  }
  --el-table-bg-color: #fcfcfc00;
  .el-scrollbar {
    border: 1px solid rgb(23, 88, 158);
    border-right: none;
    border-left: none;
  }
}
.drawer_box {
  width: 100%;
  height: 790px;
  position: relative;
  box-sizing: border-box;
  padding: 0 10px;
  .drawer_text {
    position: absolute;
    top: -28px;
    left: 2px;
    font-size: 18px;
  }
}
</style>
